import QtQuick 2.6 as Q
import QtQuick.Window 2.2


//!
//  替代默认TextEdit的一种输入框，修复了一些不协调的问题
//  该类主要是在Android中使用。QtQuick中默认的TextEdit有时会被键盘顶开，使用这个则永远不会
//  example:
//  @code
//  @code
// /
Q.Item {
    id: root
    property alias activeFocusOnPress : input.activeFocusOnPress
    property alias baseUrl : input.baseUrl
    property alias bottomPadding : input.bottomPadding
    property alias canPaste : input.canPaste
    property alias canRedo : input.canRedo
    property alias canUndo : input.canUndo
    property alias color : input.color
    property alias contentHeight : input.contentHeight
    property alias contentWidth : input.contentWidth
    property alias cursorDelegate : input.cursorDelegate
    property alias cursorPosition : input.cursorPosition
    property alias cursorRectangle : input.cursorRectangle
    property alias cursorVisible : input.cursorVisible
    property alias effectiveHorizontalAlignment : input.effectiveHorizontalAlignment
    property alias font : input.font
    property alias horizontalAlignment : input.horizontalAlignment
    property alias hoveredLink : input.hoveredLink
    property alias inputMethodComposing : input.inputMethodComposing
    property alias inputMethodHints : input.inputMethodHints
    property alias leftPadding : input.leftPadding
    property alias length : input.length
    property alias lineCount : input.lineCount
    property alias mouseSelectionMode : input.mouseSelectionMode
    property alias padding : input.padding
    property alias persistentSelection : input.persistentSelection
    property alias readOnly : input.readOnly
    property alias renderType : input.renderType
    property alias rightPadding : input.rightPadding
    property alias selectByKeyboard : input.selectByKeyboard
    property alias selectByMouse : input.selectByMouse
    property alias selectedText : input.selectedText
    property alias selectedTextColor : input.selectedTextColor
    property alias selectionColor : input.selectionColor
    property alias selectionEnd : input.selectionEnd
    property alias selectionStart : input.selectionStart
    property alias text : input.text
    property alias textDocument : input.textDocument
    property alias textFormat : input.textFormat
    property alias textMargin : input.textMargin
    property alias topPadding : input.topPadding
    property alias verticalAlignment : input.verticalAlignment
    property alias wrapMode : input.wrapMode

    signal editingFinished
    //signal linkActivated
    //signal linkHovered

    onActiveFocusChanged: {
        if (activeFocus) {
            input.forceActiveFocus()
            keyboard.show()
        }
    }

    Q.TextEdit {
        id: input
        property bool shown: y === 0

        onEditingFinished: root.editingFinished()
        //onLinkActivated: function(link){root.linkActivated(link)}
        //onLinkHovered: function(link){root.editingFinished(link)}

        width: parent.width
        height: parent.height
        y: keyboard.visible && activeFocus || Qt.platform.os === "windows" ? 0 : -Screen.height

        selectByMouse: true
    }
    Q.TextEdit {
        id: input2

        visible: !input.shown
        anchors.fill: parent

        activeFocusOnPress : input.activeFocusOnPress
        baseUrl : input.baseUrl
        bottomPadding : input.bottomPadding
        color : input.color
        cursorDelegate : input.cursorDelegate
        cursorPosition : input.cursorPosition
        cursorVisible : input.cursorVisible
        font : input.font
        horizontalAlignment : input.horizontalAlignment
        inputMethodHints : input.inputMethodHints
        leftPadding : input.leftPadding
        mouseSelectionMode : input.mouseSelectionMode
        padding : input.padding
        persistentSelection : input.persistentSelection
        readOnly : input.readOnly
        renderType : input.renderType
        rightPadding : input.rightPadding
        selectByKeyboard : input.selectByKeyboard
        selectByMouse : input.selectByMouse
        selectedTextColor : input.selectedTextColor
        selectionColor : input.selectionColor
        text : input.text
        textFormat : input.textFormat
        textMargin : input.textMargin
        topPadding : input.topPadding
        verticalAlignment : input.verticalAlignment
        wrapMode : input.wrapMode
    }
    Q.MouseArea {
        id: vkhelper
        visible: !input.shown
        anchors.fill: parent
        z: 1
        onPressed: {
            input.forceActiveFocus()
            keyboard.show()
        }
    }
    Q.QtObject {
        id: keyboard

        property bool visible: Qt.inputMethod.visible

        function show() {
            Qt.inputMethod.show()
        }
    }
}
